﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Qiang.Styles.Controls
{
    /// <summary>
    /// ColorButton.xaml 的交互逻辑
    /// </summary>
    public partial class ColorPicker : UserControl
    {
        public ColorPicker()
        {
            InitializeComponent();
            _userColor = Colors.Black;
            this.DataContext = _userColor;
            //this.btnColor.Background = new SolidColorBrush(_userColor);
        }

        Color _userColor;

        public Color UserColor
        {
            get { return _userColor; }
            set { _userColor = value; }
        }
                       
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            btnColor.Background = new SolidColorBrush(_userColor);
        }

        private void sliderRed_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _userColor.R = (byte)sliderRed.Value;
            btnColor.Background = new SolidColorBrush(_userColor);
            
        }

        private void sliderGreen_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _userColor.G = (byte)sliderGreen.Value;
            btnColor.Background = new SolidColorBrush(_userColor);
        }

        private void sliderBlue_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _userColor.B = (byte)sliderBlue.Value;
            btnColor.Background = new SolidColorBrush(_userColor);
        }

        private void sliderAlpha_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            _userColor.A = (byte)sliderAlpha.Value;
            btnColor.Background = new SolidColorBrush(_userColor);
        }
    }
}
